Ext.namespace("Nippy.Components.NodeEditors");

Nippy.Components.NodeEditors.Page = Ext.extend(Nippy.Components.NodeEditors.BasicEditor, {
    constructor: function(config){
		Nippy.Components.NodeEditors.Page.superclass.constructor.apply(this, arguments);
    }
	,initComponent: function(){
		Ext.apply(this, {
		    labelWidth: 135, // label settings here cascade unless overridden
		    frame:true,
			title: 'Страница: '.concat(this.nodeId),
		    bodyStyle:'padding:5px 5px 0',
		    width: 550,
		    defaultType: 'textfield',
		    items: [{
		            fieldLabel: 'Внутреннее название',
		            name: 'Name',
		            allowBlank:false
	        	},{
		            fieldLabel: 'URL',
		            name: 'URL',
		            allowBlank: false
		        },{
		            fieldLabel: 'Title',
		            name: 'Title',
		            allowBlank: false
		        },{
		            fieldLabel: 'META keywords',
		            name: 'MetaKeywords',
		            allowBlank: false
		        },{
		            fieldLabel: 'META description',
		            name: 'MetaDescription',
		            allowBlank: false
		        }
		        ,{
		            fieldLabel: 'Публиковать в меню',
		            name: 'InMenu',
		            xtype: 'checkbox',
		            allowBlank: false,
		            inputValue: 1
		        }
		        ,{
		            fieldLabel: 'Название для меню',
		            name: 'MenuTitle',
		            allowBlank: true
		        }
		        ,{
		            fieldLabel: 'Текст',
		            xtype: 'htmleditor',
		            name: 'HTML',
		            height: 400,
		            allowBlank: true
		        }
		    ]
		});
		Nippy.Components.NodeEditors.Page.superclass.initComponent.apply(this, arguments);
	}
	,saveClick: function(){
		var a = this.findByType('htmleditor');
		for(var i=0;i<a.length;i++){
			a[i].toggleSourceEdit(false);
		}
		this.getForm().submit({
			url: '/admin/cfg-page/',
			method: 'PUT',
			scope: this,
			params: {id: this.nodeId},
			failure: this.submitFailure,
			success: function(form, action){
				this.fireEvent('onsaved', this);
			}
		});
	}
});